<?php
/**
 * Author david you
 * Date 2024/4/3
 * Time 17:45
 */
namespace App\Http\Middleware;

use Exception;
use Illuminate\Support\Facades\Lang;

class Middleware
{

    /**
     * 返回错误信息
     * @param int $code 错误码
     * @param string $msg 错误字符串

     * @throws Exception
     */
    protected function returnError(int $code = RETURN_FAIL, string $msg = '接口请求失败')
    {
        if ($codeMsg = Lang::get($code)) {
            $msg = $codeMsg;
        }

        if (!config('app.debug')) {
            $msg = "接口请求失败";
        }

        die(apiReturn($code, $msg));
    }
}
